<?php

namespace App\Jobs;

use App\Services\PaymentService;

/**
 * 主动查询充值支付结果
 * Class PromotionJob
 * @package App\Jobs
 */
class TopUpActiveQueryResultsJob extends Job
{
    public $tries = 3;

    protected $platPayId = '';

    protected $channel = '';

    public function __construct(string $platPayId, $channel = 'wx')
    {
        $this->platPayId = $platPayId;
        $this->channel = $channel;
    }

    public function handle()
    {
        try {
            if (! (new PaymentService())->handleFztPaymentTopUp($this->platPayId, null, [], $this->channel)) {
                // 随着重试次数递增下次重试时间, 分别 2/4/6 分钟
                ($this->attempts() < $this->tries) && $this->release($this->attempts() * (2 * 60));
            }
        } catch (\Exception $e) {
            \Log::error('主动查询充值支付结果发生错误: ' . $e->getMessage());
        }
    }
}
